package com.atguigu.gmall.seckill.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.result.ResultCodeEnum;
import com.atguigu.gmall.seckill.service.SeckillBzService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/9/18 19:13
 */
@RestController
@RequestMapping("/api/activity/seckill")
public class SeckillBzController {
    @Autowired
    private SeckillBzService seckillBzService;

    ///api/activity/seckill/auth/getSeckillSkuIdStr/39
    @GetMapping("/auth/getSeckillSkuIdStr/{skuId}")
    public Result<String> getSeckillSkuIdStr(@PathVariable("skuId") Long skuId) {
        String skuIdStr = seckillBzService.getSeckillSkuIdStr(skuId);
        return Result.ok(skuIdStr);
    }

    //'/auth/checkOrder/' + skuId
    @GetMapping("/auth/checkOrder/{skuId}")
    public Result<String> checkOrder(@PathVariable("skuId") Long skuId) {
        ResultCodeEnum resultCodeEnum = seckillBzService.checkOrder(skuId);
        return Result.build("", resultCodeEnum);
    }

    //api/activity/seckill/auth/seckillOrder/null?skuIdStr=null
    @PostMapping("/auth/seckillOrder/{skuId}")
    public Result seckillOrder(@PathVariable("skuId") Long skuId,
                               @RequestParam("skuIdStr") String skuIdStr) {
        seckillBzService.seckillOrder(skuId, skuIdStr);

        return Result.ok();
    }
}
